﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Prism.Regions;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using prismapp.Event;

namespace prismapp.ViewModels
{
    internal class ViewAModel : BindableBase, IConfirmNavigationRequest
    {
        public ViewAModel(IEventAggregator aggregator)
        {
            //向MessageEvent发送消息
            aggregator.GetEvent<MessageEvent>().Publish("Hello");
        }

        private string? _title;

        public string? Title
        {
            get => _title;
            private set
            {
                _title = value;
                RaisePropertyChanged();
            }
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            if (navigationContext.Parameters.ContainsKey("Title"))
            {
                Title = navigationContext.Parameters.GetValue<string>("Title");
            }
        }

        //是否重用实例
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        //退出时调用
        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }

        //控制跳转
        public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
        {
            var res = MessageBox.Show("确认导航","提示",MessageBoxButton.YesNo) != MessageBoxResult.No;
            continuationCallback(res);
        }
    }
}